package com.sihuatech.coreagent.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sihuatech.coreagent.core.communication.entity.Province;
import com.sihuatech.coreagent.core.communication.entity.Response;
import com.sihuatech.coreagent.service.ProvinceService;
import com.sihuatech.coreagent.until.Consts;

@RestController
@RequestMapping("coreagent/province")
public class ProvinceController {
        
	@Autowired
	private ProvinceService provinceService;
	
	private static final Logger logger = LoggerFactory.getLogger(ProvinceController.class);
	
	@RequestMapping("getProvince/{id}")
	public Province getProvince(@PathVariable int id) {
		return provinceService.getProvince(id);
	}
	
	@GetMapping("getAllProvince")
	public Response getAllProvince() {

		 Response res = new Response();
		 List<Province> provinces = provinceService.getAllProvince();
		 if(provinces==null){
	    	 res.failWithMessage("没有省份信息");
	    	 return res;
		 }
      res.setCodeAndMessageAndData(Consts.SUCCESS, "获取省份信息成功", provinces);
	     return res;
	}
	
}
